//
//  WmcCloudAlbumUpdateView.swift
//  YPWatermarkCamera
//
//  Created by 周诗松 on 2022/5/30.
//

import UIKit

class WmcBadNetworkEmptyView: WmcEmptyView {
    // Internal

    /// 刷新数据
    var refreshClosure: (() -> Void)?

    override func makeUI() {
        imageView.image = "cloud_album_update".wmc_image
        addSubview(imageView)
        
        tipLabel.text = "网络异常，请检查网络"
        tipLabel.font = 16.wmc_font
        tipLabel.textColor = .wmc_grayH8_8A8A99
        addSubview(tipLabel)
        addSubview(refreshBtn)

        imageView.snp.makeConstraints { make in
            make.centerY.equalToSuperview().offset(-100)
            make.centerX.equalToSuperview()
            make.size.equalTo(100)
        }

        tipLabel.snp.makeConstraints { make in
            make.top.equalTo(imageView.snp.bottom).offset(12)
            make.left.right.equalToSuperview()
            make.height.equalTo(18)
        }

        refreshBtn.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.width.equalTo(120)
            make.height.equalTo(44)
            make.top.equalTo(tipLabel.snp.bottom).offset(24)
        }
    }

    override func bindViewAction() {
        refreshBtn.yp.addEvent { [weak self] _ in
            guard let weakSelf = self else { return }
            weakSelf.refreshClosure?()
        }
    }

    // Private

    private lazy var refreshBtn: WmcLeftImgRightTextBtn = {
        let btn = WmcLeftImgRightTextBtn(title: "刷新", image: "cloud_album_update_btn".wmc_image)
        btn.setTintColor(.wmc_white_FFFFFF)
        btn.font = 16.wmc_font
        btn.imgSize = 20.wmc_autoHor
        btn.backgroundColor = .wmc_mainTheme
        btn.layer.cornerRadius = 4
        btn.contentEdge = UIEdgeInsets(top: 0, left: 22, bottom: 0, right: 22)
        return btn
    }()
}
